package com.xxyf.service;

import com.xxyf.mapper.UserPlanMapper;
import com.xxyf.pojo.Userplan;
import com.xxyf.tools.Code;
import com.xxyf.tools.NumerUtils;
import com.xxyf.tools.Rest;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;

/**
 * @Author 小小怡飞
 * @Date 2022/9/5 10:43
 * @Version JDK 8
 */
@Service
public class PlanServiceImp implements PlanService{
    @Autowired
    UserPlanMapper userPlan;
    @Override
    public Rest grouos(Integer uid) {
        if (NumerUtils.isnotnull(uid)){
            return new Rest(userPlan.grouos(uid));
        }
        return new Rest(Code.erro,"请求错误");
    }

    @Transactional
    @Override
    public Rest add(Userplan plan) {
        if (plan==null){
            return new Rest(Code.erro,"参数错误");
        }
        long date=System.currentTimeMillis();
        plan.setGtmModifide(new Date(date));
        plan.setGtmCreate(new Date(date));
        int planadd;
        try {
            userPlan.planadd(plan);
        }catch (DataAccessException e){
            e.printStackTrace();
            return new Rest(Code.erro,"添加失败");
        }


        return new Rest(Code.succeed,"添加成功");
    }
}
